package com.baselibrary.utils

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import com.baselibrary.Constants
import com.baselibrary.R
import com.baselibrary.extension.checkValue

/**
 * @author:hanke 2022/4/29
 * desc:
 */
object EmptyViewUtil {
    var isSelf: Boolean = false
    fun isSelf(isSelf: Boolean) {
        EmptyViewUtil.isSelf = isSelf
    }

    @SuppressLint("SetTextI18n")
    fun getEmptyView(type: Int, viewGroup: ViewGroup, tip: String = ""): View {
        if (type == Constants.TYPE_GOODS_DETAIL) {
            val view = LayoutInflater.from(viewGroup.context).inflate(R.layout.layout_search_empty_view, viewGroup, false)
            val imageView = view.findViewById<ImageView>(R.id.iv_empty_img)
            val textView = view.findViewById<TextView>(R.id.tv_empty_tip)
            imageView.setImageResource(R.drawable.img_default_empty2)
            textView.text = tip
            return view
        } else if (type == Constants.TYPE_EVALUATION_LIST) {
            val view = LayoutInflater.from(viewGroup.context).inflate(R.layout.layout_evalution_empty_view, viewGroup, false)
            val imageView = view.findViewById<ImageView>(R.id.iv_empty_img)
            val textView = view.findViewById<TextView>(R.id.tv_empty_tip)
            imageView.setImageResource(R.drawable.img_default_empty2)
            textView.text = tip
            return view
        } else if (type == Constants.TYPE_SEARCH_ADDRESS) {//搜索地址
            val view = LayoutInflater.from(viewGroup.context).inflate(R.layout.layout_evalution_empty_view, viewGroup, false)
            view.findViewById<RelativeLayout>(R.id.rl_root).setBackgroundColor(ContextCompat.getColor(view.context, R.color.white))
            val imageView = view.findViewById<ImageView>(R.id.iv_empty_img)
            val textView = view.findViewById<TextView>(R.id.tv_empty_tip)
            imageView.setImageResource(R.drawable.img_default_empty2)
            textView.text = tip
            return view
        } else if (type == Constants.TYPE_VISIT_COMMENT_LIST) {//拜访评论列表
            val view = LayoutInflater.from(viewGroup.context).inflate(R.layout.layout_search_empty_view, viewGroup, false)
            val imageView = view.findViewById<ImageView>(R.id.iv_empty_img)
            val textView = view.findViewById<TextView>(R.id.tv_empty_tip)
            view.findViewById<RelativeLayout>(R.id.rl_root).setBackgroundColor(ContextCompat.getColor(view.context, R.color.white))
            imageView.setImageResource(R.drawable.img_default_empty2)
            textView.text = tip
            return view
        } else {
            val view = LayoutInflater.from(viewGroup.context).inflate(R.layout.layout_common_empty_view, viewGroup, false)
            val imageView = view.findViewById<ImageView>(R.id.iv_empty_img)
            val textView = view.findViewById<TextView>(R.id.tv_empty_tip)
            val publish = view.findViewById<TextView>(R.id.tv_publish)
            val rlRoot = view.findViewById<RelativeLayout>(R.id.rl_root)
            when (type) {

                Constants.DYNAMIC_TYPE_FORUM_CLASSIFY//讲坛分类
                -> {
                    imageView.setImageResource(R.drawable.img_default_empty2)
                    textView.text = "无相关讲坛信息"
                }
                Constants.TYPE_COLUMN_DETAIL//专栏详情
                -> {
                    imageView.setImageResource(R.drawable.img_default_empty2)
                    textView.text = "无相关文章信息"
                }
                Constants.TYPE_FOLLOW_FANS_FRIEND, Constants.TYPE_LIKE_COMMENT//关注、粉丝、好友
                -> {
                    imageView.setImageResource(R.drawable.img_default_empty3)
                    textView.text = "${tip}"
                }
                Constants.TYPE_SEARCH_WINECALLER, Constants.TYPE_LIKE_COMMENT//搜索酒窖占位
                -> {
                    imageView.setImageResource(R.drawable.img_search_no_result)
                    val layoutParams: RelativeLayout.LayoutParams = imageView.layoutParams as RelativeLayout.LayoutParams
                    layoutParams.topMargin = ScreenUtils.dip2px(viewGroup.context, 150f)
                    imageView.layoutParams = layoutParams
                    textView.text = "$tip"
                }
                Constants.TYPE_WINE_MEAL//下酒菜
                -> {
                    textView.text = tip
                    imageView.setImageResource(R.drawable.img_default_empty2)
                    rlRoot.setBackgroundColor(ContextCompat.getColor(rlRoot.context, R.color.white))
                }
                Constants.TYPE_GOOD_LIST//商品列表
                -> {
                    textView.text = tip
                    imageView.setImageResource(R.drawable.img_default_empty2)
                    rlRoot.setBackgroundColor(ContextCompat.getColor(rlRoot.context, R.color.color_F9F9F9))
                }
                Constants.TYPE_ORDER_LIST//订单列表
                -> {
                    textView.text = tip
                    imageView.setImageResource(R.drawable.img_default_empty2)
                    rlRoot.setBackgroundColor(ContextCompat.getColor(rlRoot.context, R.color.color_F9F9F9))
                }
                else -> {
                    imageView.setImageResource(R.drawable.img_default_empty)
                    textView.text = "无相关动态信息"
                }
            }
            return view
        }
    }

    //酒窖相关占位
    @SuppressLint("SetTextI18n")
    fun getEmptyView4Winecellar(viewGroup: ViewGroup, tip: String = "", @DrawableRes imgRes: Int): View {
        val view = LayoutInflater.from(viewGroup.context).inflate(R.layout.layout_demo_empty, viewGroup, false)
        val textView = view.findViewById<TextView>(R.id.tv_tip)
        val imageView = view.findViewById<ImageView>(R.id.img_tip)
        imageView.setImageResource(imgRes)
        textView.text = tip.checkValue()
        return view
    }

}
